/********************************************************************************
 *@fileName: accountFreezingLogs.jsx
 *@description: 账户冻结解冻日志
 *@author: Xhd
 *@API: 浩然
 *@Product: 马文娇
 *@date: 2024-05-13 15:00:48
 *@version: V1.0.0
**********************************************************************************/

import React, { Component } from 'react';
import TheQueryForm from '@/components/TheQueryForm';
import TheTable from '@/components/TheTable';
import ThePagination from '@/components/ThePagination';
import { apiGetAccountFreezingLogsPage } from "@/request/logs";

class AccountFreezingLogs extends Component {
  constructor(props) {
    super(props)
    this.queryFormRef = React.createRef();
    this.state = {
      columns: [
        {
          title: '用户ID',
          dataIndex: 'memberId',
          key: 'memberId',
        },
        {
          title: '用户名称',
          dataIndex: 'nickName',
          key: 'nickName',
        },
        {
          title: '操作动作',
          dataIndex: 'type',
          key: 'type',
        },
        {
          title: '操作人',
          dataIndex: 'userName',
          key: 'userName',
        },
        {
          title: '金额',
          dataIndex: 'changePrice',
          key: 'changePrice',
          render: (text, record) => {
            let price = ( text / 100 ).toFixed(2)
            return record.recordType === "0" ? text > 0 ? "-" + price + "元" : price + '元' : "+" + price + '元'
          }
        },
        {
          title: '操作时间',
          dataIndex: 'createTime',
          key: 'createTime',
        },
        {
          title: '操作备注',
          dataIndex: 'remark',
          key: 'remark',
          render: (text) => {
            return <div style={{
              maxWidth: 300,
              display: 'inline-block',
              overflow: 'hidden',
              textOverflow: 'ellipsis',
              whiteSpace: 'nowrap',
              textAlign: 'center'
            }}>
              {text}
            </div>
          },
        },
      ],
      searchOption: [
        { field: 'memberData', label: '用户ID', placeholder: '请输入用户ID或昵称', required: false, rules: [], type: 'Input', defaultValue: '' },
        {
          field: 'type', label: '操作动作', placeholder: '请选择', type: 'Select',
          options: [{ label: '钱包冻结', value: "0" }, { label: '钱包解冻', value: "1" }, { label: '礼物收益冻结', value: "2" }, { label: '礼物收益解冻', value: "3" }, { label: '分享官账户冻结', value: "4" }, { label: '分享官账户解冻', value: "5" }],
        },
        { field: 'time', label: '操作时间', placeholder: '请选择操作时间', type: 'RangePicker', required: false, rules: [], defaultValue: " " },
      ],
      dataSource: [],
      pageData: { pageNo: 1, pageSize: 10 },
      total: 0,
      searchValue: {},
    }
  }

  componentDidMount() {
    this.getData()
  }

  getData = async () => {
    const { pageData, searchValue } = this.state;
    if (searchValue.time) {
      searchValue.startDate = searchValue.time[0].format('YYYY-MM-DD')
      searchValue.endDate = searchValue.time[1].format('YYYY-MM-DD')
      delete searchValue.time
    }
    const params = { ...pageData, ...searchValue };
    await apiGetAccountFreezingLogsPage(params).then((res) => {
      if (res.code === 0) {
        this.setState({ dataSource: res.data, total: res.totalCount })
      }
    })
  }

  onFormSearch = (values) => {
    const params = { ...values };
    this.setState({ searchValue: params, pageData: { pageNo: 1, pageSize: 10 } }, () => {
      this.getData()
    })
  }

  onReset = () => {
    this.queryFormRef.formRef.resetFields();
    this.setState({ searchValue: {}, pageData: { pageNo: 1, pageSize: 10 } }, () => {
      this.getData()
    })
  }

  pageChange = (pageNo, pageSize) => {
    this.setState({ pageData: { pageNo, pageSize } }, () => {
      this.getData()
    })
  }


  render() {
    const { columns, dataSource, pageData: { pageNo, pageSize }, total, searchOption, } = this.state;
    return (<div className='p-layout-box'>
      <TheQueryForm ref={(ref) => (this.queryFormRef = ref)} show={true} option={searchOption} onReset={() => this.onReset()} onGetValues={(values) => this.onFormSearch(values)} />
      <TheTable scroll={{ x: 'max-content', y: '63vh' }} columns={columns} dataSource={dataSource} />
      <ThePagination pageNo={pageNo} pageSize={pageSize} total={total} pageChange={this.pageChange} />
    </div>)
  }
}

export default AccountFreezingLogs